package com.sl.au.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Protype;
import com.sl.au.service.MyMoneyInfoService;
@RestController
@RequestMapping(value = "/ui/myMoneyInfo")
public class myMoneyInfoController extends BaseController {
	
	@Autowired
	MyMoneyInfoService myMoneyInfoService;
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView modelAndView = this.createLayoutView("myMoneyTotal/myMoneyInfo");
		return modelAndView;
	}
	
	
	/***
	 * 获取部门饼图
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getDeptChart", method = RequestMethod.GET)
	public Map<String, Object> getDeptChart(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		String deptName =  request.getParameter("deptName");
		String arear =  request.getParameter("arear");
		String person =  request.getParameter("person");
		List list = myMoneyInfoService.getMyMoneyChartsService(0, beginDate, endDate, deptName, arear, person);
		List<Protype> returnList = new ArrayList<Protype>();
		for (Object row : list) {  
	        Object[] cells = (Object[]) row;
	        Protype protype = new Protype();
	        protype.setValue(Float.parseFloat(cells[1].toString()));
	        protype.setName(cells[0].toString());
	        returnList.add(protype);
	    }
		map.put("data", returnList);
		return map;
	}
	
	/***
	 * 获取片区饼图
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getArearChart", method = RequestMethod.GET)
	public Map<String, Object> getArearChart(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		String deptName =  request.getParameter("deptName");
		String arear =  request.getParameter("arear");
		String person =  request.getParameter("person");
		List list = myMoneyInfoService.getMyMoneyChartsService(1, beginDate, endDate, deptName, arear, person);
		List<Protype> returnList = new ArrayList<Protype>();
		for (Object row : list) {  
	        Object[] cells = (Object[]) row;
	        Protype protype = new Protype();
	        protype.setValue(Float.parseFloat(cells[1].toString()));
	        protype.setName(cells[0].toString());
	        returnList.add(protype);
	    }
		map.put("data", returnList);
		return map;
	}
	
	/***
	 * 获取人员饼图
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getPersonChart", method = RequestMethod.GET)
	public Map<String, Object> getPersonChart(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		String deptName =  request.getParameter("deptName");
		String arear =  request.getParameter("arear");
		String person =  request.getParameter("person");
		List list = myMoneyInfoService.getMyMoneyChartsService(2, beginDate, endDate, deptName, arear, person);
		List<Protype> returnList = new ArrayList<Protype>();
		for (Object row : list) {  
	        Object[] cells = (Object[]) row;
	        Protype protype = new Protype();
	        protype.setValue(Float.parseFloat(cells[1].toString()));
	        protype.setName(cells[0].toString());
	        returnList.add(protype);
	    }
		map.put("data", returnList);
		return map;
	}
	/***
	 * 获取部门柱状图
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getPersonNameChart", method = RequestMethod.GET)
	public Map<String, Object> getPersonNameChart(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		String deptName =  request.getParameter("deptName");
		String arear =  request.getParameter("arear");
		String person =  request.getParameter("person");
		int count =  Integer.parseInt(request.getParameter("count"));
		List list = myMoneyInfoService.getMyMoneyChartsService(count, beginDate, endDate, deptName, arear, person);
		List<Float> series = new ArrayList<Float>();
		List<String> Axis = new ArrayList<String>();
		for (Object row : list) {  
	        Object[] cells = (Object[]) row;
	        Axis.add(cells[0].toString());
	        series.add(Float.parseFloat(cells[1].toString()));
	    }
		map.put("Axis", Axis);
		map.put("series", series);
		return map;
	}
}
